﻿package mortal.game.manager.item
{
    import com.gengine.global.*;
    import flash.display.*;
    import flash.events.*;
    import mortal.component.gconst.*;

    public class LineBox extends Sprite
    {
        private var _lineLays:Array;
        private var _lineNum:int;
        private var _currentNum:int;
        private var _refreshStep:int;
        private var _frameCount:int;
        private var _currentLine:Sprite;
        private var _thumbParent:Sprite;

        public function LineBox()
        {
            this._lineLays = [];
            this._thumbParent = new Sprite();
            this.mouseChildren = false;
            this.mouseEnabled = false;
            this.cacheAsBitmap = true;
            return;
        }// end function

        public function updateLine(param1:int, param2:int, param3:Array, param4:Number = 0.5, param5:Number = 1, param6:Number = 1) : void
        {
            var _loc_7:int = 0;
            var _loc_9:Sprite = null;
            var _loc_10:uint = 0;
            this.dispose();
            this._refreshStep = param4 * Global.stage.frameRate;
            var _loc_8:* = param3.length;
            while (_loc_7 < _loc_8)
            {
                
                _loc_10 = param3[_loc_7];
                _loc_9 = new Sprite();
                _loc_9.graphics.lineStyle(param5, _loc_10, param6);
                _loc_9.graphics.drawRect(0, 0, param1, param2);
                _loc_9.graphics.endFill();
                _loc_9.filters = [FilterConst.colorGlowFilter(_loc_10)];
                this._lineLays.push(_loc_9);
                _loc_7++;
            }
            this._lineNum = this._lineLays.length;
            if (this._lineNum == 1)
            {
                this.addChild(this._lineLays[0]);
            }
            else if (this._lineNum > 1 && this._refreshStep > 0)
            {
                this.addEventListener(Event.ENTER_FRAME, this.onEnterFrame);
            }
            return;
        }// end function

        private function onEnterFrame(event:Event) : void
        {
            if (this._frameCount % this._refreshStep == 0)
            {
                if (this._currentLine && this.contains(this._currentLine))
                {
                    removeChild(this._currentLine);
                }
                this._currentLine = this._lineLays[this._currentNum];
                addChild(this._currentLine);
                var _loc_2:String = this;
                var _loc_3:* = this._currentNum + 1;
                _loc_2._currentNum = _loc_3;
                if (this._currentNum == this._lineNum)
                {
                    this._frameCount = 0;
                    this._currentNum = 0;
                }
            }
            var _loc_2:String = this;
            var _loc_3:* = this._frameCount + 1;
            _loc_2._frameCount = _loc_3;
            return;
        }// end function

        public function dispose() : void
        {
            var _loc_1:Sprite = null;
            if (this.parent != this._thumbParent)
            {
                this._thumbParent.addChild(this);
            }
            this._currentNum = 0;
            this._frameCount = 0;
            this._refreshStep = 0;
            this._lineNum = 0;
            this._lineLays.splice(0);
            if (this._currentLine)
            {
                if (this._currentLine.parent)
                {
                    removeChild(this._currentLine);
                }
                this._currentLine.filters = null;
                this._currentLine = null;
            }
            while (numChildren > 0)
            {
                
                _loc_1 = this.removeChildAt(0) as Sprite;
                _loc_1 = null;
            }
            this.x = 0;
            this.y = 0;
            this.removeEventListener(Event.ENTER_FRAME, this.onEnterFrame);
            return;
        }// end function

    }
}
